package com.tulele.vtool.wechat.service;

import com.tulele.vtool.bus.service.SysGzhService;
import com.tulele.vtool.model.PlatformSysInfo;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

@Scope("prototype")//多例注入
@Service
@Slf4j
public class WeixinServiceDL extends WxMpServiceImpl {

    @Autowired
    private SysGzhService sysGzhService;

    public void reSetConfigStorage(String gzhCode) {

        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(gzhCode);

        if(sysGzh!=null) {

            final WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage();

            // 设置微信公众号的appid
            config.setAppId(sysGzh.getSysGzh().getAppId());
            // 设置微信公众号的app corpSecret
            config.setSecret(sysGzh.getSysGzh().getSecret());
            // 设置微信公众号的token
            config.setToken(sysGzh.getSysGzh().getToken());
            // 设置消息加解密密钥
            config.setAesKey(sysGzh.getSysGzh().getAesKey());

            log.error("******** reSetConfigStorage_config.getAppId():"+config.getAppId()+"_*****");
            super.setWxMpConfigStorage(config);
            //this.refreshRouter();
        }
    }
}
